//============================================================================
// Name        : DocumentIndex.h
// Author      : lucmir@dcc.ufmg.br
// Description :
//============================================================================

#ifndef __DOCUMENT_INDEX_H__
#define __DOCUMENT_INDEX_H__

#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>

#include "DocumentInfo.h"

#define NOT_FOUND	0

class DocumentIndex {

	std::map<unsigned int, DocumentInfo *> idDocMap;		// Hash id -> document
	std::map<std::string, unsigned int> docIdMap;			// Hash document url -> document id
	unsigned int numDocs;									// Number of docs
	unsigned long long docsLenSum;							// Documents length sum

	public:

		DocumentIndex();
		~DocumentIndex();

		DocumentInfo *containsDoc(std::string doc);
		unsigned int insertDoc(DocumentInfo *doc);
		void insertDoc(DocumentInfo *doc, unsigned int docId);
		unsigned int getNumDocs();
		DocumentInfo *getDoc(unsigned int doc);
		unsigned int getDoc(std::string url);
		bool readUrls(std::string urlsFileName);

		void updateDocInfo(unsigned int docId, unsigned int freq,
			unsigned int numDocs, unsigned int tf);

		bool printToFile(std::string documentsFileName);
		bool readFromFile(std::string documentsFileName);
		unsigned long long getDocsLenSum();
};

#endif
